import axios from "axios";
import { getToken } from "./auth";
import config from "../config";

const apiJsonClient = axios.create({
  baseURL: config.baseURL,
  headers: {
    "Content-Type": "application/json",
    Authorization:
      "eyJyb2xlIjoiYWRtaW4iLCJpc3N1ZWRBdCI6MTczMzY1Nzk1MzYyNSwiZXhwaXJ5IjoxNzM2MjQ5OTUzNjI1LCJ1c2VySWQiOiIyIiwidXNlcm5hbWUiOiJrayJ9bXlTZWNyZXRLZXk=",
  },
});

const apiMultiPartClient = axios.create({
  baseURL: config.baseURL,
  headers: {
    Authorization:
      "eyJyb2xlIjoiYWRtaW4iLCJpc3N1ZWRBdCI6MTczMzY1Nzk1MzYyNSwiZXhwaXJ5IjoxNzM2MjQ5OTUzNjI1LCJ1c2VySWQiOiIyIiwidXNlcm5hbWUiOiJrayJ9bXlTZWNyZXRLZXk=",
  },});

apiJsonClient.interceptors.request.use(
  (config) => {
    const token = getToken();
    if (token) {
      config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

export function getRequest(url) {
  return apiJsonClient.get(url);
}

export function postRequest(url, data) {
  return apiJsonClient.post(url, data);
}

export function postNormalRequest(url, data) {
  return apiMultiPartClient.post(url, data);
}
